﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <title>登陆日志</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link href="/lobsteruiframe/layuiadmin/layui/css/layui.css" rel="stylesheet" />
    <link href="/lobsteruiframe/layuiadmin/style/admin.css" rel="stylesheet" />
    <script src="/lobsteruiframe/layuiadmin/layui/layui.js"></script>
    <script src="/jslib/jquery-3.4.1.min.js"></script>
    <script src="/jslib/lobster.js"></script>
</head>

<body>
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-header layui-form layuiadmin-card-header-auto">
                <div class="layui-inline">
                    <div class="layui-form-item">
                        <label class="layui-form-label">日志类别：</label>
                        <div class="layui-input-block">
                            <select id="logtype" name="logtype" lay-filter="LAY-sellogType">
                                <option value="0">服务端日志</option>
                                <option value="1">患者端日志</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-form-item">
                        <label class="layui-form-label">日志日期</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" id="logdate" name="logdate" placeholder=" - " style="width:250px">
                        </div>
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-form-item">
                        <button class="layui-btn layuiadmin-btn-useradmin" lay-submit
                            lay-filter="LAY-baselog-get-logrecord" id="btnSearch">
                            <i class="layui-icon layuiadmin-button-btn layui-icon-search"></i>查询
                        </button>
                    </div>
                </div>
            </div>
            <div class="layui-card-body">
                <table id="LogTable" lay-filter="LogTable"></table>
            </div>
        </div>
    </div>
</body>

</html>

<script type="text/javascript">
    lobsterlayui.main(['index', 'layer', 'form', 'element', 'table', 'laydate'], {
        data: {
            $layui: null,
            right: null,
            tablelog: null,
        },
        pageload: function (right) {
            this.data.right = right;

            this.initevent();

            this.data.tablelog = this.getBaseLogRecord();
        },
        initevent() {
            var self = this;

            //选择完日期范围后，动态查询
            layui.laydate.render({
                elem: '#logdate',
                type: "date",
                format: 'yyyy-MM-dd',
                value: new Date().format("yyyy-MM-dd") + ' ~ ' + new Date().format("yyyy-MM-dd"),
                range: '~',
                change: function (value, date, endDate) {
                    $("#logdate").val(value);
                },
                done: function (value, date, endDate) {
                    $("#logdate").val(value);
                }
            });

            //监听机构下拉框选择事件
            layui.form.on('select(LAY-sellogType)', function (data) {
                self.data.tablelog.reload({
                    where: {
                        logtype: $('#logtype').val(),//日志类别
                        logstartdate: $("#logdate").val().substr(0, 10) + " 00:00:00",     //查询日期范围之开始时间
                        logenddate: $("#logdate").val().substr(13, 10) + " 23:59:59"     //日期结束时间      
                    }
                    , page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
            });


            //查找
            layui.form.on('submit(LAY-baselog-get-logrecord)', function (data) {
                self.data.tablelog.reload({
                    where: {
                        logtype: $('#logtype').val(),//日志类别
                        logstartdate: $("#logdate").val().substr(0, 10) + " 00:00:00",     //查询日期范围之开始时间
                        logenddate: $("#logdate").val().substr(13, 10) + " 23:59:59"     //日期结束时间       
                    }
                    , page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
            });
        },
        //获取日志数据
        getBaseLogRecord: function () {
            // 显示日志数据
            return layui.table.render({
                elem: "#LogTable",
                headers: lobsterlayui.GetHeaderData(),
                where: {
                    logtype: $('#logtype').val(),//日志类别
                    logstartdate: new Date().format("yyyy-MM-dd") + " 00:00:00",                           //查询日期范围之开始时间
                    logenddate: new Date().format("yyyy-MM-dd") + " 23:59:59"                              //日期结束时间                                
                },
                height: "full-130",
                cellMinWidth: 80, //全局定义常规单元格的最小宽度
                url: '/admin/v1/syslog/GetLoginLogData',  //控制器名称，方法名称
                page: true, //开启分页
                limit: 10,
                //even: true,
                loading: true,
                cols: [[ //表头
                    { field: 'UserId', title: '用户ID', width: '150' }
                    , { field: 'Describe', title: '描叙', width: '500' }
                    , { field: 'CreateTime', title: '记录日期', width: '180' }
                ]],
                parseData: function (res) {
                    return {
                        code: res.code,
                        msg: res.msg,
                        count: res.data.count,
                        data: res.data.data
                    }
                }
            });
        }
    })

    Date.prototype.format = function (fmt) {
        var o = {
            "M+": this.getMonth() + 1,                 //月份
            "d+": this.getDate(),                    //日
            "h+": this.getHours(),                   //小时
            "m+": this.getMinutes(),                 //分
            "s+": this.getSeconds(),                 //秒
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度
            "S": this.getMilliseconds()             //毫秒
        };

        if (/(y+)/.test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        }

        for (var k in o) {
            if (new RegExp("(" + k + ")").test(fmt)) {
                fmt = fmt.replace(
                    RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            }
        }

        return fmt;
    }

</script>